package uk.ac.lkl.common.allocator.ui;



//import java.awt.Point;
//import java.awt.event.MouseEvent;

//import javax.swing.event.MouseInputAdapter;

//import uk.ac.lkl.common.allocator.AllocatorModel;
//import uk.ac.lkl.common.allocator.ScheduleObject;


public class MoveDragger<O> extends Dragger<O> {

    private int lastColumn;


    public MoveDragger(SwitchingAllocatorView<O> scheduleView) {
        super(scheduleView);
    }


    public void processMousePressed(O object, int row, int column) {
        lastColumn = column;
        // block = schedule.getBlock(object, column);
    }


    public void processMouseDragged(O object, int row, int column) {
        if (column < 0 || column >= schedule.getNumColumns())
            return;

        if (column == lastColumn)
            return;

        boolean positiveDirection = column > lastColumn;

        schedule.unallocate(object, lastColumn);

        boolean ok = schedule.pushSetAllocation(
                                                object,
                                                column,
                                                1,
                                                positiveDirection);

        if (!ok) {
            schedule.setAllocation(object, lastColumn, 1);
        }
        else {
            scheduleView.setMobileCell(object, lastColumn, false);
            scheduleView.setMobileCell(object, column, true);
            lastColumn = column;
        }

        // schedule.removeBlock(block);
        // ScheduleObject<O> newBlock = new ScheduleObject<O>(start,
        // end, object);
        // boolean addedOk = schedule.addBlock(newBlock,
        // ScheduleModel.NAllocatorModel,
        // pushDirection);
        //
        // if (!addedOk)
        // schedule.addBlock(block);
        // else {
        // // hack
        // scheduleView.setMobileCell(object, lastColumn, false);
        // scheduleView.setMobileCell(object, column, true);
        // block = newBlock;
        // lastColumn = column;
        // }
        //
    }


    public void processMouseReleased(O object, int row, int column) {

    }

}
